#!/bin/sh
#
# How to make NC package
# 1. cvs co nc
# 2. cd nc
# 3. ./addlicense
# 4. ./MAKE tar

LICENSE=LICENSE.TXT
LICENSE_FOR_C=LICENSE.TXT.C
LICENSE_FOR_S=LICENSE.TXT.S
SCRIPTS="bin/nccc bin/ncrun"

echo '/***************************************************' > $LICENSE_FOR_C
gawk '{print " * " $0 }' < $LICENSE >> $LICENSE_FOR_C
echo ' ***************************************************/' >> $LICENSE_FOR_C
echo ' ' >> $LICENSE_FOR_C

echo '###################################' > $LICENSE_FOR_S
gawk '{print "# " $0 }' < $LICENSE >> $LICENSE_FOR_S
echo '###################################' >> $LICENSE_FOR_S
echo ' ' >> $LICENSE_FOR_S

addLicenseC(){
  echo $f
  cat $LICENSE_FOR_C $f > tmpfile
  mv -f tmpfile $f
}

addLicenseS(){
  echo $f
  head -1 $f > tmpfile
  cat $LICENSE_FOR_S >> tmpfile
  gawk 'BEGIN{FLAG = 0}{if (FLAG == 0) {FLAG = 1} else {print $0}}' < $f >> tmpfile
  mv -f tmpfile $f	
  chmod +x $f
}

for f in `find src -name '*.cpp' -print`; do
  addLicenseC
done

for f in `find src -name '*.y' -print`; do
  addLicenseC
done

for f in `find include -name '*.h' -print`; do
  addLicenseC
done


for f in $SCRIPTS; do
  addLicenseS
done
